package com.atguigu.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*************************************************
                时间: 2021-05-13
                作者: 刘  辉
                描述: 
  ************************************************/
public class FirstInterceptor implements HandlerInterceptor {

    /************************************************************
     preHandle:在目标方法执行执行执行
      返回值：boolean类型，true表示放行请求,false拦截请求
      作用：权限验证,日志记录

    ************************************************************/
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        System.out.println("FirstInterceptor preHandle....");

        return true;
    }
    //postHandle：在目标方法执行之后，但是在视图渲染之前[model中数据填充到jsp页面的过程]执行
    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        System.out.println("FirstInterceptor postHandle....");
    }
    //afterCompletion在视图渲染之后执行。
    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        System.out.println("FirstInterceptor afterCompletion....");
    }
}
